﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web_froms
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //确认
        protected void btnOk_Click(object sender, EventArgs e)
        {
            var riuid = ris_uid.Text.Trim();
            var ripwd = ris_pwd.Text.Trim();
            var repwd = res_pwd.Text.Trim();
            if (riuid == "")
            {
                Response.Write(@"<script>alert('用户名不能为空！')</script>");
            }
            else
                if (ripwd == "")
            {
                Response.Write(@"<script>alert('密码不能为空！')</script>");
            }
            else
                if (repwd == "")
            {
                Response.Write(@"<script>alert('确认密码不能为空！')</script>");
            }
            else
            {
                var sql = string.Format("select * from Users where UserName='{0}'", riuid);
                var dt = DbHelper.GetDatatable(sql);
                if (dt.Rows.Count > 0)
                {
                    Response.Write(@"<script>alert('该用户已存在！')</script>");
                }
                else
                   if (ripwd != repwd)
                {
                    Response.Write(@"<script>alert('两次输入的密码不一致，请重试！')</script>");
                }
                else
                {
                    var sqlri = string.Format("insert into Users(UserName,PassWord) values('{0}','{1}')", riuid, ripwd);
                    DbHelper.ADU(sqlri);
                    Response.Write(@"<script>alert('注册成功！')</script>");
                    Response.Redirect("Login.aspx");
                }
            }
        }

        //取消
        protected void btnNo_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}